﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Drawing;
using System.Drawing.Drawing2D;

namespace sp500
{
    public partial class Form1 : Form
    {
        // company symbol
        private string companysymbolTX;
        private Sp500QuteHistoryList symbolsp500HistoryData=null;

        public Form1()
        {
            InitializeComponent();
        }

        private void loadhistoryquteButton_Click(object sender, EventArgs e)
        {
            companysymbolTX = companySymbolTXBox.Text;
            // TODO!!! input validation
            // open data base check companysymbolTX is right

            YahooDownloadFromIcharUrl yahoodownload = new YahooDownloadFromIcharUrl(companysymbolTX);
            yahoodownload.download();
            symbolsp500HistoryData = yahoodownload.getHistoryDataList();

            DataAdapter2Table dataAdapter = new DataAdapter2Table(symbolsp500HistoryData);
            dataGridView1.DataSource = dataAdapter.adapter2Datasource();

        }

        private void analysisButton1_Click(object sender, EventArgs e)
        {
            List<Sp500Dailyquote> qutelist = symbolsp500HistoryData.getHistoryqute();

            List<PointF> lowlist = new List<PointF>();
            int i=0; 
            foreach(Sp500Dailyquote qute in qutelist)
            {
                PointF point = new PointF(i, (float)qute.LowpriceTX);
                ++i;
                lowlist.Add(point);
            }

            DrawingTest.FormPicture picdisplay = new DrawingTest.FormPicture(lowlist.ToArray());
            //picdisplay.TopMost = true;
            //picdisplay.Location = this.Parent.Location;
            //this.Parent.Hide();
            picdisplay.Show(this.Parent);
        }

        private void QutePic_Click(object sender, EventArgs e)
        {
            //
        }

        private void qutepic_enter(object sender, EventArgs e)
        {
            // MessageBox.Show("Here!");
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            base.OnPaint(e);
            RectangleF picpanelsize =  this.panelInQutePicTab.ClientRectangle;
            //MessageBox.Show(picpanelsize.ToString());
            List<Sp500Dailyquote> qutelist = symbolsp500HistoryData.getHistoryqute();

            List<PointF> lowlist = new List<PointF>();
            int i = 0;
            qutelist.Reverse();
            foreach (Sp500Dailyquote qute in qutelist)
            {
                PointF point = new PointF(i, (float)qute.LowpriceTX);
                ++i;
                lowlist.Add(point);
            }
            qutelist.Reverse();
            //lowlist.Reverse();

            SizeF panelSize = new SizeF(picpanelsize.Width,picpanelsize.Height);
            DrawingTest.Drawtest1 drawpic = new DrawingTest.Drawtest1(e.Graphics, lowlist.ToArray(), panelSize);
            drawpic.draw();
        }
    }
}
